<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html lang="zh-CN">
    <head>
    <meta charset="utf-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%> 
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
        <script type="text/javascript">
            $(document).ready(function(){
               });
               //子项目保存
              var saveForm={
                    s:null,
                      t:null,
                      save:function(s,t){
                          $(t).attr("disabled",true);
                          this.s=s;
                          this.t=t;
                         /*  if($('#subItemCode').val().trim() == $('#itemValue').val().trim()){
                                  // 定制子项项目值重复，请重新输入！
                                     layer.msg('<spring:message code="dictItemValueAndItmeCodeNotRepetition"/>', {time:2000}); 
                                     $(saveForm.t).attr("disabled",false);
                                     return;
                                } */
                          if($('#subItemCd').val().trim() == $('#itemValue').val().trim()){
                                  // 定制子项项目值重复，请重新输入！
                                     layer.msg('<spring:message code="dictItemValueAndItmeCodeNotRepetition"/>', {time:2000}); 
                                     $(saveForm.t).attr("disabled",false);
                                     return;
                                }
                              //获取 iframe 数量 
                            	var frLength = window.parent.frames.length;
                            	//父画面下标 
                            	var parentIndex = frLength-2;
                          // 子项值是否重复
                          var result = window.parent.frames[parentIndex].isSubItemValueRepeate($('#itemValue').val(),$('#delIndex').val());
                          if (result == true) {
                              
                              // 定制子项项目值重复，请重新输入！
                              layer.msg('<spring:message code="subDictValeRepetition"/>', {time:2000}); 
                              $(saveForm.t).attr("disabled",false);
                              return;
                              
                          }
                          // 表单验证
                          $("#inputForm").validate({
                              submitHandler: function() {
                                  // 获取表单数据
                                  var params = $("#inputForm").serialize();
                                  // 调用后台保存子项方法
                                  $.post("${ctx}/sys/dict/saveSub", params, function(result) {
                                      if (result == "false") {
                                          // 表单重置
                                          $("#inputForm")[0].reset();
                                          $(saveForm.t).attr("disabled",false);
                                      } else {
                                          if(saveForm.s==1){
                                              // 调用父页面方法
                                              window.parent.frames[parentIndex].addItemValue();
                                              // 重置表单
                                              $("#inputForm")[0].reset();  
                                              // 下拉选框带搜索功能
                                              $("#propertyUnitCd").select2();
                                              $(saveForm.t).attr("disabled",false);
                                          }else{
                                               // 调用父页面方法
                                              window.parent.frames[parentIndex].addItemValue();
                                               // 关闭页面
                                              closeWin(); 
                                           }
                                         
                                      }
                                  }, 'json');
                                  },
                                  // 重名验证
                                  rules: {
                                   itemValue: {remote: "${ctx}/sys/dict/checkName?oldItemValue="+$('#oldItemValue').val() },
                                  },
                                  messages: {
                                   //数据值以存在
                                   itemValue: {remote: '<spring:message code="itemValue_exist"/>'},
                                  },
                                  fail: function(element,e) {  
                                      $(saveForm.t).attr("disabled",false);
                                  }
                          });
                          // 提交表单
                          $("#inputForm").submit(); 
                      } 
                  }
         
        </script>
    </head>
    <body>
        <!--头部-->
        <div class="myshop clearfix">
            <!-- 新建基准数据子项目 -->
            <p class="myshoptop fl"><spring:message code="dict_createSubDict"/></p>
            <div class="fr">
                <div class="topBtnClose" onclick="closeWin()">
                    <img src="${ctxStatic}/images/btn-close.png">
                </div>
            </div>
        </div>
        <form id="inputForm" method="post">
        <%-- <input type="hidden" id="subItemCode" name="subItemCode" value="${dict.itemValue}"/> --%>
        <input type="hidden" id="subItemCd" name="subItemCd" value="${dict.itemCode}"/>
        <input type="hidden" id="delIndex" name="delIndex" value="${dict.delIndex}"/>
            <div class="middle myshop_middle">
                <div class="code_center clearfix">
                    <div class="code_left">
                        <div class="data clearfix">
                            <!-- 数据代码 -->
                            <p class="data_id"><spring:message code="dict_itemCode"/></p>
                            <p class="fashion">${dict.itemCode}</p>
                        </div>
                        <div class="data clearfix haveToBox">
                            <!-- 数据值 -->
                            <p class="data_id"><spring:message code="dict_itemValue"/></p>
                            <input type="text"  id="itemValue" name="itemValue" value="${dict.itemValue}"    maxlength="22" data-msg-required="<spring:message code="dict_pleaseInputItemValue"/>" data-rule-required="true" data-rule-lettersnumbers="true"  data-msg-lettersnumbers="<spring:message code="dict_pleaseInputItemValue"/>" class="form-control fam">
                            <input type="hidden"  id="oldItemValue" name="oldItemValue" value="${dict.itemValue}" />
                            <p class="haveTo">*</p>
                        </div>
                        <div class="data clearfix haveToBox">
                            <!-- 数据中文 -->
                            <p class="data_id"><spring:message code="dict_itemNameCn"/></p>
                            <input type="text"  id="itemNameCn" name="itemNameCn" value="${dict.itemNameCn}"  maxlength="50" data-msg-required="<spring:message code="dict_pleaseInputItemCn"/>" data-rule-required="true" class="form-control fam">
                            <p class="haveTo">*</p>
                        </div>
                        <div class="data clearfix haveToBox">
                            <!-- 数据英文 -->
                            <p class="data_id"><spring:message code="dict_itemNameEn"/></p>
                            <input type="text"  id="itemNameEn" name="itemNameEn" value="${dict.itemNameEn}"  maxlength="50" data-msg-required="<spring:message code="dict_pleaseInputItemEn"/>" data-rule-required="true" class="form-control fam">
                            <p class="haveTo">*</p>
                        </div>
                        <div class="data clearfix">
                            <div class="fl clearfix">
                                <!-- 状态 -->
                                <p class="data_id"><spring:message code="dict_state"/></p>
                                <div class="data_rd fl">
                                    <label class="lbst">
                                        <input type="radio" name="enableFlag" value="1" checked='checked' <c:if test="${dict.enableFlag eq 1}">checked='checked'</c:if> class="rast"/><spring:message code="dict_enable"/>
                                    </label>
                                    <label class="lbst">
                                        <input type="radio" id="enableFlag_check" value="0" name="enableFlag"  <c:if test="${dict.enableFlag eq 0}">checked='checked'</c:if> class="rast" /><spring:message code="dict_disable"/>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="data clearfix">
                    <!-- 描述 -->
                    <p class="data_id"><spring:message code="dict_remarks"/>
                    <span class="txtRg">(0/100)</span>
                    </p>
                    <div class="data_ip fl">
                        <textarea class="dsp" id="remarks" name="remarks" value="${dict.remarks}"  maxlength="100">${dict.remarks}</textarea>
                    </div>
                </div>
                <div class="twobtn" style="margin-top:109px;">
                    <div class="onebtn clearfix">
                        <shiro:hasPermission name="sys:dict:edit">
                            <!-- 保存 -->
                            <button type="button" class="btn save fl" style="margin:0 auto;" onclick="saveForm.save(0,this)"><spring:message code="dict_save"/></button>
                            <!-- 保存并继续 -->
                            <button type="button" class="btn gon fr" onclick="saveForm.save(1,this)"><spring:message code="dict_saveAndcontinue"/></button>
                        </shiro:hasPermission>
                    </div>
                </div>
            </div>
        </form>
        <script>
            var windowH = window.innerHeight
                    ||document.documentElement.clientHeight
                    ||document.body.clientHeight;
            $('.middle').css('height',windowH - 40);
        </script>
    </body>
</html>
